package com.yuncool;

import lombok.extern.slf4j.Slf4j;

import java.util.*;

/**
 * @Auther XIE
 * @Date 2019/8/25 17:12
 * @Description 获取apiMessage的工具类
 * @Version 1.0
 */
@Slf4j
public class ApiMessage {

    private static HashMap<String,String> messageMap;

    static {
        initMessageMap();
    }

    private static void initMessageMap(){
        ResourceBundle bundle=ResourceBundle.getBundle("apiMessage");
        messageMap = new HashMap<>();
        Enumeration<String> keys = bundle.getKeys();
        while (keys.hasMoreElements()){
            String key=keys.nextElement();
            String value=bundle.getString(key);
            messageMap.put(key,value);
        }
    }

    public static String getMessage(String messageKey){
        String result="";
        if (null != messageMap){
            result = messageMap.get(messageKey.toUpperCase());
            if (null == result){
                log.debug("Getting system message failed. MessageKey = [" + messageKey
                        + "]");
            }
        }
        return result;
    }

}
